using UnityEngine;

namespace NodeCanvas.BehaviourTrees
{
	[AddComponentMenu("")]
	[Name("Interrupt")]
	[Category("Decorators")]
	[Description("Interrupt the child node and return Failure if the condition is or becomes true while running. Otherwise return whatever the child returns")]
	[Icon("Interruptor")]
	public class BTInterruptor : BTDecorator, ITaskAssignable
	{
		[SerializeField]
		private Object _condition;

		public Task task
		{
			get
			{
				return condition;
			}
			set
			{
				condition = (ConditionTask)value;
			}
		}

		public Object serializedTask
		{
			get
			{
				return _condition;
			}
		}

		private ConditionTask condition
		{
			get
			{
				return _condition as ConditionTask;
			}
			set
			{
				_condition = value;
				if (value != null)
				{
					value.SetOwnerSystem(base.graph);
				}
			}
		}

		protected override Status OnExecute(Component agent, Blackboard blackboard)
		{
			if (!base.decoratedConnection)
			{
				return Status.Resting;
			}
			if (!condition || !condition.CheckCondition(agent, blackboard))
			{
				return base.decoratedConnection.Execute(agent, blackboard);
			}
			if (base.decoratedConnection.connectionStatus == Status.Running)
			{
				base.decoratedConnection.ResetConnection();
			}
			return Status.Failure;
		}
	}
}
